layui.use(['layer', 'form', 'ztree', 'laydate', 'admin', 'ax', 'table', 'func', 'dict', 'formSelects', 'xmSelect','upload'], function () {
    var form = layui.form;
    var $ax = layui.ax;
    var table = layui.table;
    var func = layui.func;
    var upload = layui.upload;
    var $ = jQuery = layui.jquery;
    var dict = layui.dict; //获取自定义模块
    var formSelects = layui.formSelects;
    var xmSelect = layui.xmSelect;
    var laydate = layui.laydate;
    dict.renderDictAll(); //渲染
    //table的初始化实例

    //重新渲染select数据
    form.render('select');

    //日期时间范围
    laydate.render({
        elem: '#costingDateRange',
        range: true,
        format: 'yyyy/MM/dd'
    });

    /**
     * 系统管理--菜单管理
     */
    var Menu = {
        tableId: "menuTable",    //表格id
        condition: {
            menuId: "",
            menuName: "",
            level: ""
        }
    };
    /**
     * 初始化表格的列
     */
    Menu.initColumn = function () {
        return [[
            {field: 'businessDate', sort: true, title: '核对日期', templet: function (data) {
                    return data.businessDate.substring(0, 10);
                }},
            {field: 'rawMaterialName', sort: true, title: '食材名称'},
            {field: 'rawMaterialLossNum', sort: true, title: '食材消耗量(克)'},
            {field: 'rawMaterialSupplyNum', sort: true, title: '食材供货量(克)'},
            {field: 'rawMaterialRetainNum', sort: true, title: '食材剩余量(克)'},
            {field: 'createdAt', sort: true, title: '创建时间'},
        ]];
    };


    Menu.initTable = function(queryData) {
        var path = '/erya/rawmaterialDailyLoss/queryAll';
        if (queryData) {
            path += '?' + queryData;
        }
        return table.render({
            elem: '#' + Menu.tableId,
            url: Feng.ctxPath + path,
            page: true,
            height: "full-98",
            cellMinWidth: 100,
            cols: Menu.initColumn(),
        });
    }

    Menu.initTable(null);

    // 搜索
    $('#btnQuery').click(function () {
        var businessDate = $('#businessDate').val().trim();
        var materialCode = $('#materialCode').val().trim();
        Menu.initTable('businessDate=' +　businessDate + '&materialCode=' +　materialCode);
    });

});